package cn.zzu.Etrip.hometrip.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;

import com.example.administrator.etrip.R;

public class HomeTripHotelActivity extends AppCompatActivity {

    private Button btn1;
    private Button btn2;
    private Button btn3;
    private TextView tv1;
    private TextView tv2;
    private TextView tv3;

    private TextView desc1;
    private TextView desc2;
    private TextView desc3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        final String location = intent.getExtras().getString("text");
        switch (location) {
            case "北京":
                setContentView(R.layout.familytrip_hotel_beijing);
                break;
            case "上海":
                setContentView(R.layout.familytrip_hotel_shanghai);
                break;
            case "郑州":
                setContentView(R.layout.familytrip_hotel);
                break;
            default:
                setContentView(R.layout.familytrip_hotel);
                break;
        }

        View.OnClickListener tm=new View.OnClickListener(){

            public void onClick(View view){
                Intent intent = null;
                switch (view.getId()) {
                    case R.id.btn_hotel1 :
                        intent = new Intent(HomeTripHotelActivity.this, HomeTripPayActivity.class);
                        intent.putExtra("city1", btn1.getText().toString());
                        intent.putExtra("price1", tv1.getText().toString());
                        intent.putExtra("desc1", desc1.getText().toString());
                        startActivity(intent);
                        break;
                    case R.id.btn_hotel2 :
                        intent = new Intent(HomeTripHotelActivity.this, HomeTripPayActivity.class);
                        intent.putExtra("city1", btn2.getText().toString());
                        intent.putExtra("price1", tv2.getText().toString());
                        intent.putExtra("desc1", desc2.getText().toString());
                        startActivity(intent);
                        break;
                    case R.id.btn_hotel3 :
                        intent = new Intent(HomeTripHotelActivity.this, HomeTripPayActivity.class);
                        intent.putExtra("city1", btn3.getText().toString());
                        intent.putExtra("price1", tv3.getText().toString());
                        intent.putExtra("desc1", desc3.getText().toString());
                        startActivity(intent);
                        break;
                }
            }
        };
        tv1 = findViewById(R.id.tv_price1);
        tv2 = findViewById(R.id.tv_price2);
        tv3 = findViewById(R.id.tv_price3);
        desc1 = findViewById(R.id.tv_item1);
        desc2 = findViewById(R.id.tv_item2);
        desc3 = findViewById(R.id.tv_item3);
        btn1 = findViewById(R.id.btn_hotel1);
        if(intent.getStringArrayExtra("city1")!=null) {
            btn1.setText(intent.getStringArrayExtra("city1")[0]);
            tv1.setText(intent.getStringArrayExtra("price1")[0]);
            desc1.setText(intent.getStringArrayExtra("desc1")[0]);
        }
        btn2 = findViewById(R.id.btn_hotel2);
        if(intent.getStringArrayExtra("city1")!=null) {
            btn2.setText(intent.getStringArrayExtra("city1")[1]);
            tv2.setText(intent.getStringArrayExtra("price1")[1]);
            desc2.setText(intent.getStringArrayExtra("desc1")[1]);
        }
        btn3 = findViewById(R.id.btn_hotel3);
        if(intent.getStringArrayExtra("city1")!=null) {
            btn3.setText(intent.getStringArrayExtra("city1")[2]);
            tv3.setText(intent.getStringArrayExtra("price1")[2]);
            desc3.setText(intent.getStringArrayExtra("desc1")[2]);

        }
        btn1.setOnClickListener(tm);
        btn2.setOnClickListener(tm);
        btn3.setOnClickListener(tm);



    }
}
